﻿# Textures.py: textures module
# Written by Victor Luna Freire - victorclf@live.com
# Copyright (c) Victor Luna Freire. All rights reserved.
# Sunday, June 02, 2009 20:13:00 PM
# Python 2.6.2
import pygame
import os
from warnings import *

class TextureManager:
    def __init__(self):
        self.DEFAULT_PATH = os.path.join(os.curdir, "data", "textures", "wall")
        self.sprites_surfaces = {}
        

    def load_textures(self):
        for root, dirs, files in os.walk(self.DEFAULT_PATH):
            for f in files:
                if f[-3:] == "png":
                    try:
                        new_surface = pygame.image.load(os.path.join(root,f)).convert()
                        new_surface.set_colorkey((255,0,255),0)
                        
                    except: 
                        print "Error: failed to load - %s" % f
                        continue

                    realname = os.path.join(root.split(self.DEFAULT_PATH)[1][1:], f[:-4])
                    if os.sep != '\\': realname = realname.replace(os.sep, '\\')
                    self.sprites_surfaces[realname] = new_surface

    def get_texture(self, name):
        try:
            return self.sprites_surfaces[name]
        except:
            print "Error: texture not found - %s" % name
            print self.sprites_surfaces
            raise SystemExit


Textures = TextureManager()


